<template>
	<view class="container">
		<nav-bar></nav-bar>

		<view>
			<view class="register_text">{{getPageTitle()}}</view>
		</view>

		<view>
			<input class="info-input" maxlength="20" :placeholder="getHintText()" @input="onInput"></input>
		</view>

		<button @click="nextStep" class="btn_next_step" :disabled="btnDisable">确认</button>
	</view>
</template>

<script>
	import inputVerification from '@/common/verification.js';
	export default {
		data() {
			return {
				/**
				 * email   name
				 */
				infoType: "email",
				preKey: '', // 上一页接受数据的datakey
				btnDisable: true,
				userInput: ''
			}
		},

		onLoad: function(e) {
			this.preKey = e.key;
			this.infoType = e.infotype;
		},

		methods: {
			getPageTitle() {
				let re = "修改" + (this.infoType == "email" ? "邮箱" : (this.infoType == "name" ? "名字" : "手机号"));
				return re
			},

			getHintText() {
				let re = "输入" + (this.infoType == "email" ? "邮箱地址" : (this.infoType == "name" ? "名字" : "手机号"));
				return re
			},

			onInput(event) {
				console.log(event)
				// debugger
				var inputValue = event.detail.value
				this.userInput = event.detail.value
				if (this.isInputOk().flag)
					this.btnDisable = false;
				else
					this.btnDisable = true;
			},

			isInputOk() {
				let isNull = false
				if (this.infoType == 'email')
					isNull = inputVerification.verificationFuc({
						name: 'isEmail',
						value: this.userInput
					})
				else if (this.infoType == 'name')
					isNull = inputVerification.verificationFuc({
						name: 'isNull',
						value: this.userInput
					})
				else if (this.infoType == 'mobile')
					isNull = inputVerification.verificationFuc({
						name: 'isPhoneNum',
						value: this.userInput
					})
				return isNull
			},

			nextStep() {
				console.log("userInput : " + this.userInput)

				var pages = getCurrentPages();
				var currPage = pages[pages.length - 1]; //当前页面
				var prevPage = pages[pages.length - 2]; //上一个页面

				debugger
				if (this.infoType == 'email')
					prevPage._data.userMail = this.userInput
				else if (this.infoType == 'name')
					prevPage._data.userName = this.userInput
				else if (this.infoType == 'mobile')
					prevPage._data.userMobile = this.userInput

				uni.navigateBack(); //上一个页面数据无法修改
			}
		}
	}
</script>

<style>
	.container {
		padding: 50upx;
	}

	.register_text {
		color: #000000;
		font-size: 60upx;
	}

	.info-input {
		margin-top: 50upx;
		padding: 15upx;
		border-radius: 10px;
		border: 1px solid #aaaaaa;
	}

	.btn_next_step {
		margin-top: 150upx;
		margin-left: 0upx;
		margin-right: 0upx;
		background-color: #327FFC;
		color: #FFFFFF;
	}
</style>
